﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BeerScanOTron_Barcode
{
    public class StateContext : INotifyPropertyChanged
    {
        private IState _state;
        public event PropertyChangedEventHandler PropertyChanged;

        public StateContext()
        {
            _state = new NewUserState();
        }

        #region Properties

        public bool FirstNameEnabled
        {
            get { return _state.FirstNameEnabled; }
        }

        public bool LastNameEnabled
        {
            get { return _state.LastNameEnabled; }
        }

        public bool SaveButtonEnabled
        {
            get { return _state.SaveButtonEnabled; }
        }

        public string SaveButtonText
        {
            get { return _state.SaveButtonText; }
        }

        public string InstructionLabelText
        {
            get { return _state.InstructionLabelText; }
        }

        internal IState State
        {
            get { return _state; }
            set { _state = value; }
        }

        public string FormCaption
        {
            get { return _state.FormCaption; }
        }

        public bool LblEditUserEnabled
        {
            get { return _state.LblEditUserEnabled; }
        }

        public string LblEditUserCaption
        {
            get { return _state.LblEditUserCaption; }
        }

        public bool LblDeleteUserEnabled
        {
            get { return _state.LblDeleteUserEnabled; }
        }

        public string LblDeleteUserCaption
        {
            get { return _state.LblDeleteUserCaption; }
        }

        public Color DialogBackground
        {
            get { return _state.DialogBackground; }
        }

        #endregion

        public void Update()
        {
            NotifyChangedAllFields();
        }

        #region INotifyPropertyChanged Implementation

        private void NotifyPropertyChanged(string name)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }

        private void NotifyChangedAllFields()
        {
            NotifyPropertyChanged("FirstNameEnabled");
            NotifyPropertyChanged("LastNameEnabled");
            NotifyPropertyChanged("SaveButtonEnabled");
            NotifyPropertyChanged("InstructionLabelText");
            NotifyPropertyChanged("FormCaption");
            NotifyPropertyChanged("LblEditUserEnabled");
            NotifyPropertyChanged("LblEditUserCaption");
            NotifyPropertyChanged("LblDeleteUserEnabled");
            NotifyPropertyChanged("LblDeleteUserCaption");
            NotifyPropertyChanged("DialogBackground");
        }

        #endregion
    }
}
